using System.Reflection;
using System.Text;

namespace SAP.BusinessOne.Mackinac.Generator.Model
{
    public class Method
    {
        public Method(MethodInfo target)
        {
            TechnicalName = target.Name;
            Name = Camelize(target.Name);

            ArgumentInfo ai = new ArgumentInfo(target.ReturnParameter);
            IsVoidReturnType = (ai.Type == "void");
            ReturnTypeDefaultValue = "0";

            ReturnType = ai.Type;
            if (ai.Type == "const wstring&")
            {
                ReturnType = "wstring";
                ReturnTypeDefaultValue = "L\"\"";
            }

            InputTypes = new ArgumentInfoCollection(target.GetParameters());
        }

        private string Camelize(string p)
        {
            StringBuilder sb = new StringBuilder(p.Length);
            sb.Append(p[0].ToString().ToLower());
            sb.Append(p.Substring(1));
            return sb.ToString();
        }

        public string Name { get; private set; }
        public string TechnicalName { get; private set; }
        public bool IsVoidReturnType { get; private set; }
        public string ReturnType { get; private set; }
        public string ReturnTypeDefaultValue { get; private set; }
        public ArgumentInfoCollection InputTypes { get; private set; }
    }
}